# 文件读取
with open(r"read.txt","r",encoding="utf-8") as f:
    # print(f.read()) # 读取文件的所有内容
    print(f.read(4)) # 读取文件的指定字节

# 按行读取1
with open(r"read.txt","r",encoding="utf-8") as f:
    for a in f:  # 每个a是一行
        print(a,end="")

# enumerate() 函数的使用
# 读取一个文件的内容 加上序号之后再把内容写到另外一个文件
with open("read.txt","r",encoding="utf-8") as f:
    lines = f.readlines()
    lines = [ line.rstrip()+" #"+str(index+1)+"\n" for index,line in enumerate(lines)]  #推导式生成列表
with open("write.txt","w",encoding="utf-8") as f:
    f.writelines(lines)
